package org.lanqiao.dao;

import org.lanqiao.entity.Login;

import java.sql.*;

public class LoginDao {
    public int login (Login login){
        String URL="jdbc:mysql://localhost:3306/login";
        String USERNAME="root";
        String PWD="HZQNB666233";
        Connection connection=null;
        Statement stmt=null;
        ResultSet rs=null;
        try{
            Class.forName("com.mysql.Driver");
            connection = DriverManager.getConnection(URL,USERNAME,PWD);
            stmt=connection.createStatement();
            String sql="select count(*) from login where username = '"+login.getName()+"' and password = '"+login.getPwd()+"'";
            rs =stmt.executeQuery(sql);
            int count= -1;
            if(rs.next()){
                count = rs.getInt(1);
            }
            return count;
        }catch (ClassNotFoundException e){

            e.printStackTrace();
            return -1;
        }catch (SQLException e){
            e.printStackTrace();
            return -1;
        }catch (Exception e){

            e.printStackTrace();
            return -1;
        }finally {
            try{
                if(rs!=null) rs.close();
                if(stmt!=null) stmt.close();
                if(connection!=null)connection.close();
            }catch (SQLException e){
                e.printStackTrace();
            }

        }

    }
}
